#include "KpTestInfo.h"
#include <QFile>
#include <QFileInfo>
#include <QDirIterator>
#include "KpTestInfo.h" // for modeStr

QString KpTestInfo::formatTitle(int mode, int amount)
{
    return QString("%1%2题").arg(KpTestInfo::modeStr(KpTestInfo::KeTestMode(mode))).arg(amount);
}

QString KpTestInfo::toLine() const
{
    QString line;
    line += startTime.toString();    line += '\t';
    line += QString::number(mode);   line += '\t';
    line += QString::number(amount); line += '\t';
    line += QString::number(score);  line += '\t';
    line += QString::number(ticked);
    return line;
}

bool KpTestInfo::fromLine(const QString& line)
{
    auto tokens = line.split('\t');
    if(tokens.size() != 5)
        return false;

    startTime = QDateTime::fromString(tokens[0]);
    mode = KpTestInfo::KeTestMode(tokens[1].toInt());
    amount = tokens[2].toInt();
    score = tokens[3].toInt();
    ticked = tokens[4].toInt();

    return true;
}

QString KpTestInfo::modeStr(KeTestMode mode)
{
    static const QString modeStr[] = {
        "单词听写",
        "音标写单词",
        "英译汉",
        "汉译英"
    };

    return modeStr[mode];
}
